<template>
  <div>
    <!-- 排行榜 -->

    <div class="rankBox">
      <ul class="rankList" v-for="(item, index) in musicList" :key="index">
        <li @click="goRank(item.id)">
          <div class="rankLeft">
            <img :src="item.coverImgUrl" alt="" />
            <span>{{item.updateFrequency}}</span>
          </div>
          <div class="rankRight">
            <span v-for="(item1, index) in item.tracks" :key="index"
              >{{ item1.first }}-{{ item1.second }}</span
            >
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { rank } from "../api/api";

export default {
  name: "rank",
  data() {
    return {
      rankList: "",
      musicList: [],
    };
  },
  created() {
    rank().then((res) => {
      console.log(res);
      // this.rankList=res.list;
      for (let i = 0; i < res.list.length; i++) {
        if (i < 4) {
          this.musicList.push(res.list[i]);
        }
      }
    });
  },
  methods:{
      goRank(id){
        this.$router.push({path:"/rankList", query: {id}});
      }

    }
};
</script>
<style scoped lang="less">
// 排行榜
// .rankBox {
//   // width: 96%;
// }
.rankList {
  margin: auto;
  margin-top: 15px;
  width: 94%;
  //   overflow: hidden;
}
.rankList > li {
  margin: auto !important;
  margin-bottom: 12px !important;
  position: relative;
  overflow: hidden;
  // border: 1px solid greenyellow;
}
.rankLeft {
  position: relative;
  float: left;
  width: 100px;
  height: 100px;
  //   background-color: red;
  border-radius: 10px;
}
.rankLeft>span {
  position: absolute;
  bottom: 6px;
  left: 5px;
  font-size: 14px;
  color: #fff;
  // font-weight: 600;
}
.rankLeft > img {
  width: 100%;
  height: 100%;
  border-radius: 10px;
}
.rankRight {
  float: right;
  position: absolute;
  top: 0;
  right: 11%;
  width: 57%;
  height: 100px;
  // background-color: pink;
  padding: 10px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rankRight > span {
  display: block;
  height: 30%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rankRight > span {
  color: #666;
}
</style>
